package com.yc.mvc;

import com.yc.mvc.web.MyDispatchServlet;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/5/3
 * Email haijunzhou@hnit.edu.cn
 */
public class WebConfig implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext cxt =
                new AnnotationConfigWebApplicationContext();
        cxt.register(MvcConfig.class);

        //DispatcherServlet servlet = new DispatcherServlet(cxt);
        MyDispatchServlet servlet = new MyDispatchServlet();
        ServletRegistration.Dynamic registration =
                servletContext.addServlet("app", servlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("/");
    }
}
